'use strict';

const { DataTypes } = require('sequelize');
const sequelize = require('../../database/sequelize');

/**
 * 游记评论模型
 */
const TravelNoteComment = sequelize.define(
  'TravelNoteComment',
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '评论ID'
    },
    note_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '游记ID',
      field: 'note_id'
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '用户ID',
      field: 'user_id'
    },
    parent_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      comment: '父评论ID（用于回复功能）',
      field: 'parent_id'
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: '评论内容'
    },
    like_count: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '点赞数',
      field: 'like_count'
    },
    status: {
      type: DataTypes.ENUM('normal', 'hidden', 'deleted'),
      allowNull: false,
      defaultValue: 'normal',
      comment: '状态：normal-正常，hidden-隐藏，deleted-已删除'
    },
    created_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
      comment: '创建时间',
      field: 'created_at'
    },
    updated_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
      comment: '更新时间',
      field: 'updated_at'
    }
  },
  {
    tableName: 'travel_note_comments',
    timestamps: true,
    underscored: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    indexes: [
      {
        name: 'idx_note_id',
        fields: ['note_id']
      },
      {
        name: 'idx_user_id',
        fields: ['user_id']
      },
      {
        name: 'idx_parent_id',
        fields: ['parent_id']
      }
    ]
  }
);

module.exports = TravelNoteComment;

